<template>
  <el-dialog title="图纸选择" v-if="showFlag" :visible.sync="showFlag" :modal="false" width="60%" center>
    <el-table v-loading="loading" :data="drawingList" @current-change="handleCurrent" @row-dblclick="handleRowDbClick">
      <el-table-column width="50" align="center">
        <template v-slot="scope">
          <el-radio v-model="selectedId" :label="scope.row.id" @change="handleRowChange(scope.row)">
            {{ '' }}
          </el-radio>
        </template>
      </el-table-column>
      <el-table-column label="产品名称" align="center" prop="itemName"/>
      <el-table-column label="产品图号" align="center" prop="itemDrawCode"/>
      <el-table-column label="图纸分类名称" align="center" prop="drawingTypeName"/>
      <el-table-column label="图纸集名称" align="center" prop="drawingName"/>
      <el-table-column label="图纸集版本" align="center" prop="version"/>
    </el-table>

    <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirmSelect">确 定</el-button>
      <el-button @click="showFlag = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { listDrawing } from "@/api/mes/md/drawing";

export default {
  name: 'DrawingSelectSingle',
  data() {
    return {
      showFlag: false,
      // 遮罩层
      loading: true,
      selectedId: undefined,
      selectedRows: undefined,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产品BOM关系表格数据
      drawingList: [],
      // 弹出层标题
      title: '',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        itemCode: this.productCode,
        status: 1,
        processAuthorization: 1,
      }
    };
  },
  props: {
    productCode: null,
  },
  watch: {
    productCode: function (val) {
      this.queryParams.itemCode = val;
      this.getList();
    }
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询图纸集管理列表 */
    getList() {
      this.loading = true;
      listDrawing(this.queryParams).then(response => {
        this.drawingList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleCurrent(row) {
      if (row) {
        this.selectedRows = row;
      }
    },
    handleRowDbClick(row) {
      if (row) {
        this.selectedRows = row;
        this.$emit('onSelected', this.selectedRows);
        this.showFlag = false;
      }
    },
    // 单选选中数据
    handleRowChange(row) {
      if (row) {
        this.selectedRows = row;
      }
    },

    //确定选中
    confirmSelect() {
      if (this.selectedId == null || this.selectedId == 0) {
        this.$notify({
          title: '提示',
          type: 'warning',
          message: '请至少选择一条数据!'
        });
        return;
      }
      this.$emit('onSelected', this.selectedRows);
      this.showFlag = false;
    }
  }
};
</script>

